//
//  YZSwineArchieveCell.m
//  VET
//
//  Created by 刘文靖 on 2018/7/18.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSwineArchieveCell.h"
#import "YZPigModel.h"
#import "YZAutoItemModel.h"
#import "YZDashLineView.h"
@interface YZSwineArchieveCell()
@property (nonatomic, weak) UILabel *earMarkLabel; ///<耳标号
@property (nonatomic, weak) UIButton *manageBtn; ///<管理按钮
@property (nonatomic, weak) UILabel *swineClassLabel; ///<猪只分类
@property (nonatomic, weak) UILabel *swineSexLabel; ///<猪只性别
@property (nonatomic, weak) UILabel *swineDateAgeLabel; ///<猪只日龄
@property (nonatomic, weak) UILabel *swineSpeciesLabel; ///<猪只品种
@property (nonatomic, weak) UILabel *swineStateLabel; ///<猪只状态
@end
@implementation YZSwineArchieveCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.contentView.backgroundColor = kColorWithHex(0xf5f5f5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *mainView = [[UIView alloc] init];
        mainView.layer.contents = (__bridge id)[UIImage imageNamed:@"card_background"].CGImage;
        [self.contentView addSubview:mainView];
        [mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(12);
            make.bottom.offset(0);
            make.right.offset(-12);
        }];
//        YZDashLineView *dashLineView = [[YZDashLineView alloc] initWithFrame:CGRectMake(25, 68, kScreenWidth - 74, 1)];
//        dashLineView.backgroundColor = kColorWithHex(0xE0E0E0);
//        [mainView addSubview:dashLineView];
        ///<耳标号
        UILabel *earMarkLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x434343);
            label.font = [UIFont fontWithName:@"SFCompactDisplay-Bold" size:18];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(18);
                make.left.offset(26);
            }];
            label;
        });
        self.earMarkLabel = earMarkLabel;
        
        UILabel *earMarkDescLabel = [[UILabel alloc] init];
        earMarkDescLabel.text = @"耳标号";
        earMarkDescLabel.textColor = kColorWithHex(0x9B9B9B);
        earMarkDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
        [mainView addSubview:earMarkDescLabel];
        [earMarkDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(earMarkLabel.mas_bottom).offset(6);
            make.left.mas_equalTo(earMarkLabel);
        }];
        
        
        ///<管理按钮
        UIButton *manageBtn = ({
            UIButton *btn = [[UIButton alloc] init];
            [btn setTitle:@"管理" forState:UIControlStateNormal];
            [btn setTitleColor:kColorWithHex(0x32BE60) forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-25);
                make.top.offset(25);
            }];
            btn;
        });
        self.manageBtn = manageBtn;
        CGFloat lebelH = 14;
        ///<猪只分类
        UILabel *swineClassDescLabel = [[UILabel alloc] init];
        swineClassDescLabel.text = @"分类";
        swineClassDescLabel.textColor = kColorWithHex(0x9B9B9B);
        swineClassDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:swineClassDescLabel];
        [swineClassDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(earMarkDescLabel.mas_bottom).offset(33);
            make.left.mas_equalTo(earMarkLabel);
            make.height.mas_equalTo(lebelH);
        }];
        
        UILabel *swineClassLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(swineClassDescLabel.mas_right).offset(5);
                make.top.height.mas_equalTo(swineClassDescLabel);
            }];
            label;
        });
        self.swineClassLabel = swineClassLabel;
        ///<猪只性别
        UILabel *swineSexLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-76);
                make.top.height.mas_equalTo(swineClassLabel);
            }];
            label;
        });
        self.swineSexLabel = swineSexLabel;
        
        UILabel *swineSexDescLabel = [[UILabel alloc] init];
        swineSexDescLabel.text = @"性别";
        swineSexDescLabel.textColor = kColorWithHex(0x9B9B9B);
        swineSexDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:swineSexDescLabel];
        [swineSexDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.height.mas_equalTo(swineSexLabel);
            make.right.mas_equalTo(swineSexLabel.mas_left).offset(-5);
        }];
        
        ///<猪只日龄
        UILabel *swineDateDscLabel = [[UILabel alloc] init];
        swineDateDscLabel.text = @"日龄";
        swineDateDscLabel.textColor = kColorWithHex(0x9B9B9B);
        swineDateDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:swineDateDscLabel];
        [swineDateDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(swineClassDescLabel.mas_bottom).offset(12);
            make.left.height.mas_equalTo(swineClassDescLabel);
        }];
        
        UILabel *swineDateAgeLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(swineDateDscLabel.mas_right).offset(5);
                make.top.height.mas_equalTo(swineDateDscLabel);
            }];
            label;
        });
        self.swineDateAgeLabel = swineDateAgeLabel;
        ///<猪只品种
        UILabel *swineSpeciesDscLabel = [[UILabel alloc] init];
        swineSpeciesDscLabel.text = @"品种";
        swineSpeciesDscLabel.textColor = kColorWithHex(0x9B9B9B);
        swineSpeciesDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:swineSpeciesDscLabel];
        [swineSpeciesDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.mas_equalTo(swineDateAgeLabel);
            make.left.mas_equalTo(swineSexDescLabel);
        }];
        
        UILabel *swineSpeciesLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(swineSpeciesDscLabel.mas_right).offset(5);
                make.top.height.mas_equalTo(swineSpeciesDscLabel);
            }];
            label;
        });
        self.swineSpeciesLabel = swineSpeciesLabel;
        ///<猪只状态
        UILabel *swineStateDscLabel = [[UILabel alloc] init];
        swineStateDscLabel.text = @"状态";
        swineStateDscLabel.textColor = kColorWithHex(0x9B9B9B);
        swineStateDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:swineStateDscLabel];
        [swineStateDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(swineDateDscLabel.mas_bottom).offset(12);
            make.left.height.mas_equalTo(swineDateDscLabel);
        }];
        
        UILabel *swineStateLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(swineStateDscLabel.mas_right).offset(5);
                make.top.height.mas_equalTo(swineStateDscLabel);
            }];
            label;
        });
        self.swineStateLabel = swineStateLabel;
        @weakify(self)
        [[self.manageBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            if (self.delegate && [self.delegate respondsToSelector:@selector(cellDidClickManage:)]) {
                [self.delegate cellDidClickManage:self];
            }
            
        }];
        
    }
    return self;
}

- (void)setModel:(YZPigModel *)model{
    _model = model;
    self.earMarkLabel.text = model.earMark;
    self.swineClassLabel.text = model.swineClass.itemValue;
    self.swineSexLabel.text = model.swineSex.itemValue;
    self.swineDateAgeLabel.text = model.pigBirthdateStr;
    self.swineSpeciesLabel.text = model.swineSpecies.itemValue?:@"未确定";
    self.swineStateLabel.text = model.swineState.itemValue?:@"未确定";
}

@end
